//
//  CYFinanceMemberCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/8.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYFinanceMemberCell.h"



@implementation CYFinanceMemberCellObject

@end



@interface CYFinanceMemberCell ()

@property(nonatomic, strong)UILabel *memberLabel;
@property(nonatomic, strong)UILabel *amountLabel;
@property(nonatomic, strong)UILabel *dateLabel;
@property(nonatomic, strong)UILabel *timeLabel;

@property(nonatomic, strong)UILabel *mLabel;
@property(nonatomic, strong)UILabel *aLabel;
@property(nonatomic, strong)UILabel *dLabel;

@property(nonatomic, strong)UIImageView *bottomLine;

@end


@implementation CYFinanceMemberCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.mLabel = [self titleLabelWithText:@"投资用户"];
        [self.contentView addSubview:self.mLabel];
        
        self.aLabel = [self titleLabelWithText:@"投资金额"];
        [self.contentView addSubview:self.aLabel];
        
        self.dLabel = [self titleLabelWithText:@"投资时间"];
        [self.contentView addSubview:self.dLabel];
        
        self.memberLabel = [self contentLabel];
        [self.contentView addSubview:self.memberLabel];
        
        self.amountLabel = [self contentLabel];
        [self.contentView addSubview:self.amountLabel];
        
        self.dateLabel = [self contentLabel];
        [self.contentView addSubview:self.dateLabel];
        
        self.timeLabel = [self contentLabel];
        [self.contentView addSubview:self.timeLabel];
        
        self.bottomLine = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:HEXCOLOR(@"ECECEC") size:CGSizeMake(1, 1)]];
        [self.contentView addSubview:self.bottomLine];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 65;
}

- (BOOL)shouldUpdateCellWithObject:(CYFinanceMemberCellObject *)object
{
    self.memberLabel.text = object.member;
    
    self.amountLabel.text = object.amount;
    
    self.dateLabel.text = object.date;
    
    self.timeLabel.text = object.time;
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.mLabel.left = 20;
    
    self.dLabel.right = self.contentView.width - 40;
    
    self.aLabel.centerX = (self.dLabel.left - self.mLabel.right) / 2 + self.mLabel.right;
    
    [self.memberLabel sizeToFit];
    self.memberLabel.left = self.mLabel.left;
    self.memberLabel.centerY = self.contentView.height / 2;
    
    [self.amountLabel sizeToFit];
    self.amountLabel.left = self.aLabel.left;
    self.amountLabel.centerY = self.memberLabel.centerY;
    
    [self.dateLabel sizeToFit];
    [self.timeLabel sizeToFit];
    self.dateLabel.left = self.dLabel.left;
    self.timeLabel.left = self.dLabel.left;
    self.dateLabel.centerY = 23;
    self.timeLabel.centerY = self.contentView.height - 23;
    
    self.bottomLine.width = self.contentView.width - 20;
    self.bottomLine.height = 1 / SCREEN_SCALE;
    self.bottomLine.right = self.contentView.width;
    self.bottomLine.bottom = self.contentView.height;
}

#pragma mark - Private Method
- (UILabel *)titleLabelWithText:(NSString *)text
{
    UILabel *label = [[UILabel alloc] init];
    label.hidden = YES;
    label.text = text;
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = HEXCOLOR(@"444444");
    [label sizeToFit];
    return label;
}

- (UILabel *)contentLabel
{
    UILabel *label = [[UILabel alloc] init];
    label.textColor = HEXCOLOR(@"666666");
    label.font = [UIFont systemFontOfSize:14];
    return label;
}

@end
